type callBack = (hour: number, minute: number, second: number) => void
export default class TimeDown {
    second: number
    interval: any
    fun: callBack
    constructor(millisecond: number, fun: callBack) {
        this.second = Math.floor((millisecond - new Date().getTime()) / 1000)
        this.fun = fun
        this.interval = setInterval(() => {
            if (this.second < 0) {
                return
            }
            let hour = Math.floor(this.second / 3600)
            let minute = Math.floor((Math.floor(this.second) % 3600) / 60)
            let second = (Math.round(this.second) % 3600) % 60
            fun(hour, minute, second)
            this.second--
        }, 1000)
    }
    stop() {
        clearInterval(this.interval)
    }
    reset(millisecond: number) {
        this.second = Math.floor((millisecond - new Date().getTime()) / 1000)
    }
}
